package com.ly.algorithm.DataStructures.recursion;

/**
 * @Classname Queen
 * @Description TODO
 * @Date 2020/4/23 15:46
 * @Author 冷心影翼
 */
public class Queen {



    private static int max = 8;

    private static int[] arr = new int[max];

    private static int count = 0;

    public static void main(String[] args) {
        put(0);
        System.out.println(count);
    }

    public static void put(int n) {
        if(n == max) {
            for (int i = 0; i < arr.length; i++) {
                System.out.print(arr[i]+" ");
            }
            System.out.println();
            count++;
            return ;
        }
        for(int i=0;i<max;i++) {
            arr[n] = i;
            if(judge(n)) {
                put(n+1);
            }
        }
    }

    public static boolean judge(int n) {
        for(int i=0;i<n;i++) {
            if(arr[i] == arr[n] || (n-i)==Math.abs(arr[i] - arr[n])) {
                return false;
            }
        }
        return true;
    }
}
